package display
{
	import flash.events.Event;
	import flash.utils.getTimer;
	
	/**
	 * 游戏效果显示对象
	 * 有些效果需要8方向
	 * @author gcxk721
	 * 2012-7-3
	 * 下午1:41:36
	 */
	public class QhEffectMovieClip extends QhMovieClip
	{
		
		/**
		 * 一个效果的所有帧数据 
		 */
		protected var frameLst : Vector.<Vector.<QhBitmap>>;
		
		/**
		 * 当前正在播放的帧数据 
		 */
		protected var curLst : Vector.<QhBitmap>;		
		
		private const delay : int = 80;
		
		public function QhEffectMovieClip()
		{
			super();
		}
		
		/**
		 * 设置帧
		 * 2维数组 
		 * @param value
		 * 
		 */
		public function setEffectFrames(value : Vector.<Vector.<QhBitmap>>) : void
		{
			frameLst = value;
		}
		
		/**
		 * 检查当前方向的帧序列是否存在 
		 * @param dir
		 * @return 
		 * 
		 */
		public function checkDirection(dir : int) : Boolean
		{
			return frameLst[dir] == null ? false : true;
		}
		
		//????????????????????效率   效率  
		//实际上是手动在降低帧频
		private var startTime : int = 0;
		override public function play():void
		{
			startTime = getTimer();
			super.play();
		}
		
		private var time : int = 0;
		override protected function onEnterFrameHandler(evt:Event):void
		{
			var tmp : int = getTimer();
			time += (tmp - startTime);
			startTime = tmp;
			if(time > delay)
			{
				time = 0;
				super.onEnterFrameHandler(evt);
			}
		}
		
		/**
		 * 设置当前需要显示的方向 
		 * @param dir
		 * 
		 */
		public function setDirection(dir : int) : void
		{
			if(frameLst != null && checkDirection(dir))
			{
				curLst = frameLst[dir];
			}
		}
		
		override protected function skipFrame():void
		{
			var qhBitmap : QhBitmap = curLst[curIndex];
			if(qhBitmap != null && qhBitmap.bmd != null)
			{
				bmp.bitmapData = qhBitmap.bmd;
				bmp.x = qhBitmap.x;
				bmp.y = qhBitmap.y;
			}
		}
		
	}
}